//package com.mmy.fta.trade.server.service.impl;
//
//import com.mmy.fta.cargo.api.facade.CargoService;
//import com.mmy.fta.cargo.api.model.CargoInfoDTO;
//import com.mmy.fta.coldtruck.api.ColdTruckService;
//import com.mmy.fta.coldtruck.api.dto.TruckOrderDTO;
//import com.mmy.fta.trade.server.dao.OrderDao;
//import com.mmy.fta.trade.server.dto.DriverOrderMsgDTO;
//import com.mmy.fta.trade.server.dto.ShipperOrderMsgDTO;
//import com.mmy.fta.trade.server.entity.OrderEntity;
//import com.mmy.fta.trade.server.util.SmsUtil;
//import com.mmy.fta.trade.server.websocket.ShipperWebSocketTest;
//import com.mmy.fta.usercenter.api.MembershipService;
//import com.mmy.fta.usercenter.api.UserService;
//import com.mmy.fta.usercenter.dto.DriverDTO;
//import com.mmy.fta.usercenter.dto.ShipperDTO;
//import io.manbang.ironman.api.mq.consumer.MessageListener;
//import io.manbang.ironman.api.mq.consumer.MessageRoute;
//import io.manbang.ironman.api.rpc.annotation.RPCReference;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//
//import java.io.IOException;
//import java.util.Objects;
//
///**
// * @author qiang.lin
// * @since 2021/11/4
// */
//@Slf4j
//@MessageListener(key = "fta-trade-consumer", topic = "fta-training-trade")
//public class MessageConsumerService {
//
//    @RPCReference
//    UserService userService;
//
//    @RPCReference
//    CargoService cargoService;
//
//    @RPCReference
//    MembershipService membershipService;
//
//    @Autowired
//    OrderDao orderDao;
//
//    @Autowired
//    MessageProduceService messageProduceService;
//
//    @Autowired
//    ShipperWebSocketTest shipperWebSocket;
//
//    @RPCReference
//    ColdTruckService coldTruckService;
//
//    @MessageRoute({"fta-order", "fta-membership-driver", "fta-membership-shipper"})
//    public void consumerOrderNumber(String orderNumber) {
//        OrderEntity orderEntity = orderDao.queryOrderDetail(orderNumber);
//
//        CargoInfoDTO cargoInfoDTO = cargoService.queryCargoInfobyCargoId(orderEntity.getCargoId());
//        DriverDTO driverDTO = userService.queryDriverInfoByOpenId(orderEntity.getCarrierOpenid()).getData();
//        ShipperDTO shipperDTO = userService.queryByOpenId(orderEntity.getConsignorOpenid()).getData();
//
//        Integer orderStatus = 0;
//
//        if (orderEntity.getStatus() == 1) {
//            //司机下单，发货主
//
//            if(cargoInfoDTO.getStandardCargo()){
//                TruckOrderDTO truckOrderDTO = new TruckOrderDTO();
//
//                truckOrderDTO.setOrderNumber(orderNumber);
//                truckOrderDTO.setCargoId(orderEntity.getCargoId());
//                truckOrderDTO.setTruckNo(driverDTO.getDriverCarNo());
//                truckOrderDTO.setDriverName(driverDTO.getUserName());
//
//                try{
//                    coldTruckService.generateColdTruckOrder(truckOrderDTO);
//                }catch (Exception e){
//                    log.info(e.toString());
//                }
//            }
//
//            orderStatus = 1;
//        } else if (orderEntity.getStatus() == 6) {
//            //司机卸货，发货主
//            orderStatus = 6;
//        } else if (orderEntity.getStatus() == 0 && orderEntity.getInvoiceType() == 1) {
//            //司机取消，发货主
//
//            userService.updateShipperForCancelOrderByDriver(orderEntity.getConsignorOpenid());
//            orderStatus = 3;
//        } else if (orderEntity.getStatus() == 0 && orderEntity.getInvoiceType() == 2) {
//            //货主取消，发司机
//            orderStatus = 4;
//        }else if(orderEntity.getStatus() == 7){
//            //货主收货
//        }
//        messageProduceService.produceOrderMsg(orderNumber, cargoInfoDTO.getDeposit(), cargoInfoDTO.getLoadTime(),
//                cargoInfoDTO.getLoadAddress(), driverDTO.getTelephone(), cargoInfoDTO.getCargoName(),
//                driverDTO.getUserName(), cargoInfoDTO.getUnloadingAdress(), cargoInfoDTO.getOpenId(), orderStatus);
//    }
//
//    @MessageRoute({"fta-order-driver"})
//    public void consumerDriverOrder(DriverOrderMsgDTO driverOrderMsgDTO) throws IOException {
//
//        log.info("MQ-Consumer-driverOrderMsgDTO:{}", driverOrderMsgDTO);
//
//        if (driverOrderMsgDTO.getOrderStatus() == 4) {
//            //666614 短信-告知司机,货主取消
//            SmsUtil.sendSms(driverOrderMsgDTO.getDriverPhoneNumber(), "666614");
//            String driverCancelMsg = "您已的订单已被货主取消，请尽快前往小程序查看。666614";
//            log.info("货主取消-发送短信给司机：{}", driverCancelMsg);
//
//            String driverOpenId = orderDao.queryOrderDetail(driverOrderMsgDTO.getOrderNumber()).getCarrierOpenid();
//            shipperWebSocket.sendSomeoneInfo("货主取消", driverOpenId);
//            log.info("订单号：{}-websocket-货主取消-发给司机:{}", driverOrderMsgDTO.getOrderNumber(), driverOpenId);
//        }
//
//
//        if (driverOrderMsgDTO.getOrderStatus() == 2) {
//            String driverOpenId = orderDao.queryOrderDetail(driverOrderMsgDTO.getOrderNumber()).getCarrierOpenid();
//
//            shipperWebSocket.sendSomeoneInfo("货主同意", driverOpenId);
//            log.info("websocket-货主同意-发给司机-{}", driverOpenId);
//        }
//        if (driverOrderMsgDTO.getOrderStatus() == 20) {
//
//            String driverOpenId = orderDao.queryOrderDetail(driverOrderMsgDTO.getOrderNumber()).getCarrierOpenid();
//            shipperWebSocket.sendSomeoneInfo("货主拒绝", driverOpenId);
//            log.info("订单号：{}-websocket-货主拒绝-发给司机:{}", driverOrderMsgDTO.getOrderNumber(), driverOpenId);
//        }
//        if (driverOrderMsgDTO.getOrderStatus() == 7) {
//            String driverOpenId = orderDao.queryOrderDetail(driverOrderMsgDTO.getOrderNumber()).getCarrierOpenid();
//            shipperWebSocket.sendSomeoneInfo("货主收货", driverOpenId);
//            log.info("订单号：{}-websocket-货主收货-发给司机{}", driverOrderMsgDTO.getOrderNumber(), driverOpenId);
//
//
//        }
//    }
//
//
//    @MessageRoute({"fta-order-shipper"})
//    public void consumerShipperOrder(ShipperOrderMsgDTO shipperOrderMsgDTO) throws IOException {
//
//        log.info("MQ-Consumer-shipperOrderMsgDTO:{}", shipperOrderMsgDTO);
//
//        if (shipperOrderMsgDTO.getOrderStatus() == 1) {
//
//
//
//            String shipperAgreeOrderMsg = "您的从" + shipperOrderMsgDTO.getLoadAddress() + "发往" + shipperOrderMsgDTO.getUnloadingAddress() +
//                    "的" + shipperOrderMsgDTO.getCargoName() + "已由" + shipperOrderMsgDTO.getDriverName().charAt(0) + "师傅支付订金，请您尽快前往小程序查看。";
//            //666621 提醒货主，司机已下单
//            SmsUtil.sendSms(shipperOrderMsgDTO.getShipperPhoneNumber(), "666621");
//            log.info("司机下单-发送短信给货主：{}{}", shipperAgreeOrderMsg, 666621);
//
//            String shipperOpenId = orderDao.queryOrderDetail(shipperOrderMsgDTO.getOrderNumber()).getConsignorOpenid();
//            shipperWebSocket.sendSomeoneInfo("司机下单", shipperOpenId);
//            log.info("订单号：{}-websocket-司机下单-发给货主{}", shipperOrderMsgDTO.getOrderNumber(), shipperOpenId);
//        }
//
//        if (shipperOrderMsgDTO.getOrderStatus() == 3) {
//            //666614 短信-告知货主,司机取消
//            SmsUtil.sendSms(shipperOrderMsgDTO.getShipperPhoneNumber(), "666623");
//            String driverCancelToShipperMsg = "您已的订单已被司机取消，请尽快前往小程序查看。666623";
//            log.info("发送短信给司机：{}", driverCancelToShipperMsg);
//
//            String shipperOpenId = orderDao.queryOrderDetail(shipperOrderMsgDTO.getOrderNumber()).getConsignorOpenid();
//            shipperWebSocket.sendSomeoneInfo("司机取消",shipperOpenId);
//            log.info("订单号{}-websocket-司机取消-发给货主{}",shipperOrderMsgDTO.getOrderNumber(),shipperOpenId);
//        }
//
//        if (shipperOrderMsgDTO.getOrderStatus() == 5) {
//            //司机装货
//
//            String shipperOpenId = orderDao.queryOrderDetail(shipperOrderMsgDTO.getOrderNumber()).getConsignorOpenid();
//            shipperWebSocket.sendSomeoneInfo("司机装货",shipperOpenId);
//            log.info("订单号：{}-websocket-司机装货-发给货主:{}",shipperOrderMsgDTO.getOrderNumber(),shipperOpenId);
//        }
//
//        if (shipperOrderMsgDTO.getOrderStatus() == 6) {
//            String shipperReceiveOrderMsg = "您的从" + shipperOrderMsgDTO.getLoadAddress() + "发往" + shipperOrderMsgDTO.getUnloadingAddress() +
//                    "的" + shipperOrderMsgDTO.getCargoName() + "已由" + shipperOrderMsgDTO.getDriverName().charAt(0) + "师傅运输完成并且已卸货，请您尽快查收。";
//            //666621 提醒货主，司机已卸货
//            SmsUtil.sendSms(shipperOrderMsgDTO.getShipperPhoneNumber(), "666626");
//            log.info("司机下单-发送短信给货主：{}", shipperReceiveOrderMsg);
//
//            String shipperOpenId = orderDao.queryOrderDetail(shipperOrderMsgDTO.getOrderNumber()).getConsignorOpenid();
//            shipperWebSocket.sendSomeoneInfo("司机装货",shipperOpenId);
//            log.info("订单号：{}-websocket-司机装货-发给货主:{}",shipperOrderMsgDTO.getOrderNumber(),shipperOpenId);
//        }
//
//
//    }
//}
